﻿@{
    Layout = null;
}

<div style="height:46vh">
    <div class="col-3 pr-0" style="display: none">
        <label id="Common-GroupAndUser-SiteGroupID">@ViewData["SiteGroupID"]</label>
    </div>
    <div class="col-lg-5 float-left pr-0 pl-0">
        <label class="font-rfs-modal border-radius-noright noRightBorder">非组用户</label>
        <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 pre-scrollable overflow-auto" style="height: 46vh;">
            <table id="GroupAndUser-tabAllUser" class="table table-striped table-bordered table-sm table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>登录名</th>
                        <th>姓名</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
    <div class="col-lg-2 float-left">
        <button id="Common-chevron-left" class="input-group-text" title="全部移除" style="margin-top:130px;"><i class="bi-chevron-double-left" style="font-size:0.7rem"></i></button>
        <button id="Common-chevron-right" class="input-group-text" title="全部添加"><i class="bi-chevron-double-right" style="font-size:0.7rem"></i></button>
    </div>
    <div class="col-lg-5 float-right pr-0 pl-0">
        <label class="font-rfs-modal border-radius-noright noRightBorder">组用户</label>
        <div class="table-responsive-sm shadow p-0 bg-white rounded col-md-12 pre-scrollable overflow-auto" style="height:46vh">
            <table id="GroupAndUser-tabGroupUser" class="table table-striped table-bordered table-sm table-hover">
                <thead>
                    <tr>
                        <th>ID</th>
                        <th>登录名</th>
                        <th>姓名</th>
                    </tr>
                </thead>
                <tbody></tbody>
            </table>
        </div>
    </div>
</div>
<div class="text-right">
    <button id="Common-GroupAndUser-confirm" class="btn btn-primary font-rfs" data-dismiss="modal">关闭</button>
</div>

<script>

    $(document).ready(function () {
        LoadAllUser();
        LoadGroupUsers();
    });

    function LoadAllUser() {
        var columns = [{ field: "id", visible: false }, { field: "identityName" }, { field: "fullName" }];

        $('#GroupAndUser-tabAllUser').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
        $('#GroupAndUser-tabAllUser').bootstrapTable({
            method: 'post',
            url: "GetGroupUsers",
            dataType: "json",  // 服务器端返回值类型
            contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
            queryParams: function (params) {
                var data = {
                    SiteGroupId: $("#Common-GroupAndUser-SiteGroupID").html(),
                    Exclude:"true"
                };
                return data;
            },
            dataField: "rows",
            uniqueId: "id",          // 设置主键
            locale: "zh-CN",
            columns: columns,
            onDblClickRow: function (row, $element, field) {
                $.post("AddGroupUsers", {
                    SiteGroupId: $("#Common-GroupAndUser-SiteGroupID").html(),
                    Users: row.id
                }, function (data) {
                    if (data.indexOf("成功") >= 0) {
                        LoadGroupUsers();
                        $('#GroupAndUser-tabAllUser').bootstrapTable('removeByUniqueId', row.id);
                    } else {
                        alert(data);
                    }
                });
            },
            silent: true,
            formatLoadingMessage: function () {
                return "请稍等，正在加载中...";
            },
            formatNoMatches: function () {
                return '无符合条件的记录';
            },
            onLoadError: function (data) {
                $('#GroupAndUser-tabAllUser').bootstrapTable('removeAll');
            },
            onLoadSuccess: function (data) {
                SetBootstrapStyle();
            },
            formatShowingRows: function (pageFrom, pageTo, totalRows) {
                // return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
            },
            formatRecordsPerPage: function (pageNumber) {
                return " 每页显示" + pageNumber + '条记录';
            }
        });
    }

    function LoadGroupUsers() {
        var columns = [{ field: "id", visible: false }, { field: "identityName" }, { field: "fullName" }];

        $('#GroupAndUser-tabGroupUser').bootstrapTable('destroy'); // 这行代码必须加，否则数据无法刷新
        $('#GroupAndUser-tabGroupUser').bootstrapTable({
            method: 'post',
            url: "GetGroupUsers",
            dataType: "json",  // 服务器端返回值类型
            contentType: "application/x-www-form-urlencoded; charset=UTF-8", // 如果是 POST 请求，这个属性必须加
            queryParams: function (params) {
                var data = {
                    SiteGroupID: $("#Common-GroupAndUser-SiteGroupID").html(),
                    Exclude: "false"
                };
                return data;
            },
            dataField: "rows",
            uniqueId: "id",          // 设置主键
            locale: "zh-CN",
            columns: columns,
            onDblClickRow: function (row, $element, field) {
                $.post("RemoveGroupUsers", {
                    SiteGroupId: $("#Common-GroupAndUser-SiteGroupID").html(),
                    Users: row.id
                }, function (data) {
                    if (data.indexOf("成功") >= 0) {
                        LoadAllUser();
                        $('#GroupAndUser-tabGroupUser').bootstrapTable('removeByUniqueId', row.id);
                    } else {
                        alert(data);
                    }
                });
            },
            silent: true,
            formatLoadingMessage: function () {
                return "请稍等，正在加载中...";
            },
            formatNoMatches: function () {
                return '无符合条件的记录';
            },
            onLoadError: function (data) {
                $('#GroupAndUser-tabGroupUser').bootstrapTable('removeAll');
            },
            onLoadSuccess: function (data) {
                SetBootstrapStyle();
            },
            formatShowingRows: function (pageFrom, pageTo, totalRows) {
                // return "正在显示第" + pageFrom + "到第" + pageTo + "条记录，总共" + totalRows + "条记录 ";
            },
            formatRecordsPerPage: function (pageNumber) {
                return " 每页显示" + pageNumber + '条记录';
            }
        });
    }

    $("#Common-chevron-left").click(function () {
        var users = '';
        $("#GroupAndUser-tabGroupUser").find("tbody").find("tr").each(function () {
            users = users + $(this).attr("data-uniqueid") + ',';
        });

        $.post("RemoveGroupUsers", {
            SiteGroupId: $("#Common-GroupAndUser-SiteGroupID").html(),
            Users: users
        }, function (data) {
            if (data.indexOf("成功") >= 0) {
                LoadAllUser();
                $('#GroupAndUser-tabGroupUser').bootstrapTable('destroy');
            } else {
                alert(data);
            }
        });
    });

    $("#Common-chevron-right").click(function () {
        var users = '';
        $("#GroupAndUser-tabAllUser").find("tbody").find("tr").each(function () {
            users = users + $(this).attr("data-uniqueid") + ',';
        });

        $.post("AddGroupUsers", {
            SiteGroupId: $("#Common-GroupAndUser-SiteGroupID").html(),
            Users: users
        }, function (data) {
            if (data.indexOf("成功") >= 0) {
                LoadGroupUsers();
                $('#GroupAndUser-tabAllUser').bootstrapTable('destroy');
            } else {
                alert(data);
            }
        });
    });

</script>
